package com.study.youlai.common.util;

import cn.hutool.json.JSONObject;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName: HttpsUtil
 * @Description:
 * @Author: li
 * @Date: 2025/1/18 9:09
 * @Version 1.0
 **/
public class HttpsUtil {

    /**
     * get请求
     */
    public static String get(String url){
        HttpHeaders headers = new HttpHeaders();
        MediaType mediaType = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(mediaType);
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.getForObject(url, String.class);
        return result;
    }


    public static void main(String[] args) {
        String url = "https://restapi.amap.com/v3/weather/weatherInfo?city=411400&key=cdfe8d09b3daa431e0cb64011b7fd1d9";
        String s = HttpsUtil.get(url);
        System.out.println(s);
        JSONObject object = new JSONObject(s);
//        WeatherModel jb = (WeatherModel)JSONObject.toJavaObject(object, WeatherModel.class);
        System.out.println(object);


    }
}
